<!DESCRIPTION>A script that checks the number of characters in a form box, and if it exceeds the predetermined number, cancels the form submission, and asks the surfer to reenter data.
<!/DESCRIPTION>
<!CATEGORY>form and form validation<!/CATEGORY>
<!SCRIPT>
<!-- START OF SCRIPT -->
<script>
<!--
function checkchars(cur){
//change max length to determine below
var maxlength=50
if (cur.chars.value.length>maxlength){
alert("Please restrain your input to 50 or less characters!")
return false
}
}
//-->
</script>
<form onsubmit="return checkchars(this)">
<strong>In 50 chars or less, please type a short description of yourself:</strong><br><textarea rows="5" cols="38" name="chars"></textarea>
<br><input type="submit" value="Submit!">
</form>
<!-- END OF SCRIPT -->
<!/SCRIPT>
<!PREVIEW>
<!-- START OF SCRIPT -->
<script>
<!--
function checkchars(cur){
//change max length to determine below
var maxlength=50
if (cur.chars.value.length>maxlength){
alert("Please restrain your input to 50 or less characters!")
return false
}
}
//-->
</script>
<form onsubmit="return checkchars(this)">
<strong>In 50 chars or less, please type a short description of yourself:</strong><br><textarea rows="5" cols="38" name="chars"></textarea>